
$(function(){
  // 对项目进行初始化
  $('form').bootstrapValidator({
    fields: {
      username: {
        validators: {
          notEmpty: {
            message: '用户名不能为空'
          },
          stringLength: {
            min: 2,
            max: 12,
            message: '用户名长度必须在2到12位之间'
          }
          , callback: {
            message: 'mao用户名不存在'
          }
        }
      },
      password: {
        validators: {
          notEmpty: {
            message: '密码不能为空'
          },
          stringLength: {
            min: 6,
            max: 12,
            message: '密码长度必须在6到12位之间'
          }, callback: {
            message: 'mao密码错误'
          }
        }
      }
    },
    feedbackIcons: {
      valid: 'glyphicon glyphicon-ok',
      invalid: 'glyphicon glyphicon-remove',
      validating: 'glyphicon glyphicon-refresh'
    },

  })

  $('form').on('success.form.bv', function (e) {
    e.preventDefault();
    console.log(123);
    $.ajax({
      type: 'post',
      url: '/employee/employeeLogin',
      data: $('form').serialize(),
      success: function (info) {
        console.log(info);
        if (info.error === 1000) {
          // alert('用户名不存在');
          $('form').data('bootstrapValidator').updateStatus('username','INVALID','callback');
        }
        if (info.error === 1001) {
          // alert('密码错误');
          $('form').data('bootstrapValidator').updateStatus('password','INVALID','callback');
        }
        if (info.success) {
          location.href = 'index.html';
        }

      }
    })
  })

  $('button[type=reset]').on('click', function () {
    $('form').data('bootstrapValidator').resetForm();
  })
  
})